<template>
	<view class="f24r col363636">
		<view class="pt10r pl10r borB1SE8e8e8">
			<button class="w160r borRad10r lh70r colFff f26r disInBlo backCol409EFF p0"
				@click="cliAddRoomBtn"
			>
				新增房间
			</button>
		</view>
		<view class="pl20r pr20r">
			<view class="mt20r borRad10r bSha0010u0rgb00001 backImgLiGrTBDeedfdaFff overHid"
				v-for="item in tempList" :key="item.id" @click="goRoomDetail(item)"
			>
				<view class="disFlex aliItCenter pl20r pr20r mt20r mb20r">
					<view class="flex1 f26r foWeiBold">
						{{item.name}}
					</view>
					<view class="w120r teAliRight">
						<text class="w100r lh46r disInBlo teAliCenter bor1SE6a23c colE6a23c borRad25r"
							@click.stop="cliOpenDoor(item.id)"
						>
							开门
						</text>
					</view>
				</view>
				<view class="pl20r pr20r pb20r">
					<view class="disFlex lh50r">
						<view class="flex1">
							<text class="col7a7a7a">
								起订：
							</text>
							{{item.hour}}小时
						</view>
						<view class="flex1 teAliCenter">
							<text class="col7a7a7a">
								原价：
							</text>
							<text class="colCe2e37">
								¥{{item.price}}
							</text>
							/小时
						</view>
						<view class="flex1 teAliRight">
							<text class="col7a7a7a">
								适用：
							</text>
							{{item.people_count}}人
						</view>
					</view>
					<view class="disFlex lh50r">
						<view :class="['flex1']">
							<text class="col7a7a7a">
								必购套餐：
							</text>
							{{
								item.set_meal_type == 1 ? '是' :
								item.set_meal_type == 2 ? '否' : item.set_meal_type
							}}
						</view>
						<view class="flex1 teAliRight">
							<text class="col7a7a7a">
								房间id：
							</text>
							{{item.id}}
						</view>
					</view>
					<view class="disFlex aliItCenter h50r">
						<view :class="['flex1',
								item.type == 1 ? 'col47ce68' : 'colC72d21'
							]"
						>
							<text class="col7a7a7a">
								房间开放/关闭：
							</text>
							{{
								item.type == 1 ? '开放' :
								item.type == 2 ? '关闭' : item.type
							}}
						</view>
						<view class="w120r teAliRight">
							<text class="w100r lh46r disInBlo teAliCenter bor1S67c23a col67c23a borRad25r"
								@click.stop="cliCircuitBreaker1(item.id)"
							>
								断路器
							</text>
						</view>
					</view>
				</view>
			</view>
			<view class="lh100r teAliCenter col999" v-if="tempList.length">
				已加载全部
			</view>
			<view class="lh100r teAliCenter col999" v-if="tempList.length == 0">
				暂无数据
			</view>
		</view>
	</view>
</template>

<script>
import { inquiryToLogin } from '@/utils/utils.js'
import { getRoomList, teaOpenDoor,
	teaOpenSwitch } from '@/utils/api.js'
export default {
	data() {
		return {
			token: '',
			tempList: [],
		}
	},
	onLoad() {
		
	},
	onShow() {
		inquiryToLogin().then(res => {
			this.token = res;
			this.getDataList1();
		});
	},
	onPullDownRefresh() {
		this.getDataList1(() => {
			uni.stopPullDownRefresh();
		});
	},
	onReachBottom() {
		
	},
	methods: {
		getDataList1(callBack) {
			uni.showLoading({ title: '加载中...' })
			getRoomList({token: this.token}).then(res1 => {
				if(res1.data && res1.data.length) {
					this.tempList = res1.data;
				}
				uni.hideLoading();
				if(callBack) callBack();
			})
		},
		cliAddRoomBtn() {
			uni.navigateTo({ url: '/pages/index/addRoomDetail?type=1' })
		},
		goRoomDetail(item) {
			uni.setStorageSync('roomDetail', item);
			uni.navigateTo({
				url: '/pages/index/roomDetail'
			})
		},
		cliOpenDoor(rid) {
			uni.showModal({
				title: '提示', content: '确定开门？', confirmColor: '#99c043',
				success:res1 => {
					if (res1.confirm) {
						teaOpenDoor({
							token: this.token, rid
						}).then(res2 => {
							uni.showToast({
								title: '开门成功', duration: 3000
							})
						})
					}
				}
			})
		},
		cliCircuitBreaker1(rid) {
			uni.showActionSheet({
				itemList: ['开启断路器', '关闭断路器'],
				success:res1 => {
					if(res1.tapIndex == 0) {
						console.log(11)
						this.cliCircuitBreaker2(rid, 1);
					}else if(res1.tapIndex == 1) {
						console.log(22)
						this.cliCircuitBreaker2(rid, 2);
					}
				}
			})
		},
		cliCircuitBreaker2(rid, type) {
			teaOpenSwitch({
				token: this.token, rid, type
			}).then(res1 => {
				uni.showToast({
					title: `${type == 1 ? '开启' : '关闭'}成功`, duration: 3000
				})
			})
		}
	}
}
</script>
<style>
</style>